﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BlogLite.Models;
using BlogLite.Models.Database;
using Ninject;
using BlogLite.Helpers;

namespace BlogLite.Controllers
{
    [HandleErrorWithElmah]
    public class HomeController : Controller
    {
        [Inject]
        public IBlogLiteRepository BlogLiteRepository { get; set; }

        //
        // GET: /

        [HttpGet]
        public ActionResult Index()
        {
            ViewBag.Tags = BlogLiteRepository.Tags;
            return View(BlogLiteRepository.Posts);
        }

        //
        // GET: /Error

        [HttpGet]
        public ActionResult Error()
        {
            return View();
        }

        //
        // GET: /Error404

        [HttpGet]
        public ActionResult Error404()
        {
            return View();
        }

        //
        // GET: /Post

        [HttpGet]
        public ActionResult Post(int id)
        {
            var post = BlogLiteRepository.GetPostByPostId(id);

            if (post == null)
                return RedirectToAction("Error404");

            ViewBag.Tags = BlogLiteRepository.Tags;

            return View(post);
        }
    }
}
